<template>
  <div class="box">
    <div class="avatar">
      <img src="../../assets/logo.png" alt="" />
    </div>
    <!-- 表单 -->
    <el-form
      label-width="0px"
      class="form-box"
      :model="ruleForms"
      :rules="rules"
      ref="inReset"
    >
      <el-form-item prop="username" >
        <el-input prefix-icon="iconfont icon-user" v-model="ruleForms.username">
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          prefix-icon="iconfont icon-3702mima"
          v-model="ruleForms.password"
        >
        </el-input>
      </el-form-item>
      <el-row class="row-box">
        <el-button type="primary" @click="que">确定</el-button>

        <el-button type="info" @click="reset">重置</el-button>
      </el-row>
    </el-form>
  </div>
</template>
    
<script>
export default {
  data() {
    return {
      ruleForms: {
        username: "admin",
        password: "123456",
      },
      rules: {
        username: [
          { required: true, message: "请名称", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请密码", trigger: "blur" },
          { min: 6, max: 16, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    reset() {
      console.log(this);
      this.$refs["inReset"].resetFields();
     
    },
    que(){
      this.$refs.inReset.validate(async (val)=>{
        if(!val){return }
        const {data:res}= await this.$http.post('login',this.ruleForms)
        if(res.meta.status!==200){return this.$message('失败')}
        // console.log(res);
        this.$message.success('成功')
        window.sessionStorage.setItem('toank',res.data.token)
        this.$router.push('/home')

      })
    }
  },
};
</script>

<style lang="less" scoped>
.box {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 450px;
  height: 300px;
  background-color: #fff;
  .avatar {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 130px;
    height: 130px;
    border-radius: 50%;
    padding: 10px;
    background-color: #fff;
    border: 1px solid #eee;
    box-shadow: 0 0 10px 1px #eee;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
  .form-box {
    width: 100%;
    position: absolute;
    bottom: 0;
    padding: 20px;
    box-sizing: border-box;
    .row-box {
      display: flex;
      justify-content: flex-end;
    }
  }
}
</style>